package com.blog.admin.controller;

import com.blog.admin.service.BlogResourcesService;
import com.blog.admin.vo.BlogResourcesVO;
import com.blog.util.Result;
import com.blog.vo.PageVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tangqj
 * @Description
 * @create 2020/2/18 15:14
 */
@RestController
@RequestMapping("blogResourcesController")
public class BlogResourcesController {
    @Autowired
    BlogResourcesService blogResourcesService;


    /**
     * 资源
     * @param page
     * @param blogResourcesVO
     * @return
     */
    @RequestMapping("getBlogResources")
    public Map<String,Object> getBlogResources(PageVO page,BlogResourcesVO blogResourcesVO){
        PageInfo<BlogResourcesVO> result = blogResourcesService.getBlogResources(page,blogResourcesVO);
        Map<String,Object> data = new HashMap<>();
        data.put("count", result.getTotal());
        return Result.responeAjaxMap(true,"", result.getList(),data);
    }

    /**
     * 点点滴滴
     * @param page
     * @param blogResourcesVO
     * @return
     */
    @RequestMapping("getBlogTime")
    public Map<String,Object> getBlogTime(PageVO page,BlogResourcesVO blogResourcesVO){
        PageInfo<BlogResourcesVO> result = blogResourcesService.getBlogTime(page,blogResourcesVO);
        Map<String,Object> data = new HashMap<>();
        data.put("count", result.getTotal());
        return Result.responeAjaxMap(true,"", result.getList(),data);
    }

    @RequestMapping("insertBlogResources")
    public Map<String,Object> insertBlogResources(BlogResourcesVO blogResourcesVO){
        boolean result = blogResourcesService.insertBlogResources(blogResourcesVO);
        return Result.responeAjaxMap(result,  result?"操作成功":"操作失败", "",null);
    }

    @RequestMapping("updateBlogResources")
    public Map<String,Object> updateBlogResources(BlogResourcesVO blogResourcesVO){
        boolean result = blogResourcesService.updateBlogResources(blogResourcesVO);
        return Result.responeAjaxMap(result,  result?"操作成功":"操作失败", "",null);
    }

    @RequestMapping("deleteBlogResourcesById")
    public Map<String,Object> deleteBlogResourcesById(String id){
        boolean result = blogResourcesService.deleteBlogResourcesById(id);
        return Result.responeAjaxMap(result,  result?"操作成功":"操作失败", "",null);
    }
}
